package org.justdroid.justdroid;

import java.util.ArrayList;

import android.app.Application;
import android.speech.tts.TextToSpeech;

public class TTS extends Application{
	private static TextToSpeech tts = null;

	  public static TextToSpeech getObject() {
	    return tts;
	  }
	  
	  public static void setObject(TextToSpeech obj) {
	    tts = obj;
	  }
	  
	  public static void speak(String message) {
		  try {
			  TTS.tts.speak(message, TextToSpeech.QUEUE_FLUSH, null);
		  }
		  catch(Exception e) {
			  e.printStackTrace();
		  }
	  }
	  
	  public static void stop() {
		  TTS.tts.stop();
	  }
	  
	  public static boolean isSpeaking() {
		  return tts.isSpeaking();
	  }
	  
	  /** Function to read the number from left to right, one digit at a time **/
	 public static String readNumber(String number) {
		//call a function to split the number into digits and return an ArrayList
		ArrayList<String> digits = splitNumber(number);
		String listDigits = "";
		for (String digit : digits)
		{
		    listDigits += " " + digit;
		}
		return listDigits;	
	}
		
	/** Function to split a number into digits and return an ArrayList **/
	public static ArrayList<String> splitNumber(String number) {
		ArrayList<String> digits = new ArrayList<String>();
		for(int i=0; i<number.length(); i++) {
			digits.add(number.substring(i, i+1));
		}
		return digits;
	}
}
